import type { DragElementConfig } from '../../../../../lib/drag_handler'
import type { PlatformTypeValue } from '../../../../../types/interfaces'
import { SUPPORTED_PLATFORMS } from '../../../../../types/constants'
import { BianStyle } from './other/bian'
import { GreasyForkStyle } from './other/greasy_fork'
import { BaiduStyle } from './search/baidu_style'
import { BingStyle } from './search/bing_style'
import { CSDNStyle } from './search/csdn_style'
import { GoogleStyle } from './search/google_style'
import { JueJinStyle } from './search/juejin_style'
import { SoStyle } from './search/so_style'
import { SogouStyle } from './search/sogou_style'
import { ZhiHuStyle } from './search/zhihu_style'

/**
 * 博客平台样式
 */
export const BLOG_PLATFORM_STYLES: Partial<Record<PlatformTypeValue, any>> = {
  [SUPPORTED_PLATFORMS.CSDN]: CSDNStyle,
  [SUPPORTED_PLATFORMS.ZHI_HU]: ZhiHuStyle,
  [SUPPORTED_PLATFORMS.JUE_JIN]: JueJinStyle,
}

/**
 * 搜索平台样式
 */
export const SEARCH_PLATFORM_STYLES: Partial<Record<PlatformTypeValue, any>> = {
  [SUPPORTED_PLATFORMS.BAI_DU]: BaiduStyle,
  [SUPPORTED_PLATFORMS.GOOGLE]: GoogleStyle,
  [SUPPORTED_PLATFORMS.BING]: BingStyle,
  [SUPPORTED_PLATFORMS.SO_GOU]: SogouStyle,
  [SUPPORTED_PLATFORMS.SO]: SoStyle,
}

/**
 * 其他平台样式
 */
export const OTHER_PLATFORM_STYLES: Partial<Record<PlatformTypeValue, any>> = {
  [SUPPORTED_PLATFORMS.GREASY_FORK]: GreasyForkStyle,
}

/**
 * 所有平台样式
 */
export const ALL_PLATFORM_STYLES: Partial<Record<PlatformTypeValue, any>> = {
  ...BLOG_PLATFORM_STYLES,
  ...SEARCH_PLATFORM_STYLES,
  ...OTHER_PLATFORM_STYLES,
}

/**
 * 页面加载数样式
 */
export const PAGE_NUM_STYLES: Partial<Record<PlatformTypeValue, any>> = {
  [SUPPORTED_PLATFORMS.GREASY_FORK]: GreasyForkStyle,
  [SUPPORTED_PLATFORMS.BAI_DU]: BaiduStyle,
  [SUPPORTED_PLATFORMS.BING]: BianStyle,
}

/**
 * 标题清理配置类型
 */
export interface TitleCleanupConfig {
  /**
   * 平台名称（用于从标题中移除）
   * @example "知乎"
   */
  platformName?: string
  /**
   * 需要移除的尾部特殊字符
   * @example "_-" 表示移除下划线和连字符
   */
  trailingChars?: string
  /** 标题选择器 */
  titleSelector?: string
}

/**
 * 搜索平台选择器配置
 */
export interface SearchSelectorConfig {
  selector: string
  container: string
}

export interface SearchAdBadgeOptions {
  onPrepare?: (config: AdResultSelectors) => void
  config: AdResultSelectors
}
export type SearchPageAdBadgeOptions = Partial<Record<string, SearchAdBadgeOptions>>

/**
 * 搜索框下拉菜单类型
 */
export enum SearchDropdownType {
  History = 'history',
  HotRank = 'hotRank',
  Suggestions = 'suggestions',
}

/**
 * 搜索框下拉菜单配置接口
 */
interface SearchDropdownSelectors {
  /** 下拉菜单容器 */
  wrapper: string
  /** 下拉菜单列表 */
  menu: string
  /** 搜索热榜 */
  hotRank?: string
  /** 搜索建议 */
  suggestions: string
  /** 搜索历史 */
  history: string
  /** 清除历史记录按钮 */
  clearHistoryBtn: string
  /** 清除历史记录按钮文本 */
  clearHistoryText: string
}

/**
 * 搜索结果配置接口
 */
interface SearchResultSelectors {
  /** 搜索结果容器 */
  container: string
  /** 搜索结果项 */
  item: string
}

/**
 * 广告结果配置接口
 */
export interface AdResultSelectors {
  /** 广告结果容器 */
  container: string
  /** 广告结果项 */
  item: string
  itemTitle?: string
}

/**
 * 搜索框相关选择器配置接口
 */
interface SearchBoxSelectors {
  /** 搜索输入框 */
  input: string
  /** 搜索表单 */
  form?: string
  /** 搜索下拉菜单相关 */
  dropdown: SearchDropdownSelectors
}

/**
 * 搜索基础选择器配置接口
 */
export interface SearchBaseSelectors {
  /** 搜索框 */
  searchBox: SearchBoxSelectors
  /** 普通搜索结果 */
  result: SearchResultSelectors
  /** 广告结果 */
  adResult: AdResultSelectors
  /** 右侧侧边栏 */
  rightAside: DragElementConfig
}

/**
 * 搜索平台页面选择器配置
 */
export type SearchPageSelectors = Partial<Record<string, SearchBaseSelectors>>
/**
 * 搜索平台页面标题清理配置
 */
export type SearchPageTitleCleanupConfig = Partial<Record<string, TitleCleanupConfig>>
